//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package com.ww.springboot.boot.utils;

import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.Locale;
import java.util.Map;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringUtils;

public class DateUtil {
    public static final SimpleDateFormat YYYY_MM_DD = new SimpleDateFormat("yyyyMMdd");
    public static final String MONTH = "yyyy-MM";
    public static final String DATE = "yyyy-MM-dd";
    public static final String DATE_MM_DD = "MM-dd HH:mm";
    public static final String DATETIME = "yyyy-MM-dd HH:mm:ss";
    public static final String FULL_DATETIME = "yyyyMMddHHmmssSSS";
    public static final String MSEC = "yyyy-MM-dd HH:mm:ss.SSS";
    public static final String NOSPLIT_MDHM_DATETIME = "yyyyMMddHHmmss";
    public static final String NORMAL_DATETIME_FORMAT = "yyyy-MM-dd HH:mm:ss";
    public static final String NORMAL_DATETIME_FORMAT_CN = "yyyy年MM月dd日 HH时mm分";
    public static final String NORMAL_MONTHDATETIME_FORMAT_CN = "MM月dd日 HH时mm分";
    public static final String NORMAL_MONTHDATE_FORMAT_CN = "MM月dd日";
    public static final String NORMAL_DATETIME_FORMAT_NO_SECOND = "yyyy-MM-dd HH:mm";
    public static final String NORMAL_DATETIME_FORMAT_HOUR = "yyyy-MM-dd HH";
    public static final String NORMAL_DATE_FORMAT = "yyyy-MM-dd";
    public static final String NOSPLIT_DATE_FORMAT = "yyyyMMddHHmmssS";
    public static final String SLASHPLIT_DATE_FORMAT = "yyyy/MM/dd HH:mm";
    public static final String SLASHPLIT_DATE = "yyyy/MM/dd";
    public static final DateFormat DATE_TIME_FORMAT = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    public static String FORMAT_FULL = "yyyy-MM-dd HH:mm:ss.S";
    public static String DATE_MM_dd = "MM/dd";
    private static final Object LOCKOBJ = new Object();
    private static Map<String, ThreadLocal<SimpleDateFormat>> SDFMAP = new HashMap();
    private static Pattern pattern = Pattern.compile("[0-9]*");
    public static final String DT_FORMAT_STRING = "yyyy-MM-dd HH:mm:ss.SSS";
    public static final String DT_FORMAT_STRING_PATTERN = "^\\d{4}-\\d{2}-\\d{2} \\d{2}\\:\\d{2}\\:\\d{2}\\.\\d{3}$";
    public static final String DT_FORMAT_STRING_NO_MILL_SECOND = "yyyy-MM-dd HH:mm:ss";
    public static final String TIME_FORMAT_STRING_NO_MILL_SECOND = "MM-dd HH:mm:ss";
    public static final String DT_FORMAT_STRING_DATE = "yyyy-MM-dd";
    public static final String DT_FORMAT_STRING_DATE_PATTERN = "^\\d{4}-\\d{2}-\\d{2}$";
    public static final String DT_FORMAT_MILL_SECOND_PATTERN = "^\\d+$";
    public static final String DT_FORMAT_STRING_YYYYMMDDHHMMSS = "yyyyMMddHHmmss";
    public static final String DT_FORMAT = "dd/MM/yyyy";
    public static final String DT_FORMAT_STRING_NO_MILL_SECOND_PATTERN = "^\\d{4}-\\d{2}-\\d{2} \\d{2}\\:\\d{2}\\:\\d{2}$";

    public DateUtil() {
    }

    private static SimpleDateFormat getDateFormat(final String pattern) {
        ThreadLocal<SimpleDateFormat> tl = (ThreadLocal)SDFMAP.get(pattern);
        if (tl == null) {
            synchronized(LOCKOBJ) {
                tl = (ThreadLocal)SDFMAP.get(pattern);
                if (tl == null) {
                    tl = new ThreadLocal<SimpleDateFormat>() {
                        protected SimpleDateFormat initialValue() {
                            return new SimpleDateFormat(pattern);
                        }
                    };
                    SDFMAP.put(pattern, tl);
                }
            }
        }

        return (SimpleDateFormat)tl.get();
    }

    public static Date parse(String strDate, String dateFormat) throws ParseException {
        return getDateFormat(dateFormat).parse(strDate);
    }

    public static Date getDateStartTime(Date d, int days) {
        Calendar c1 = Calendar.getInstance();
        c1.setTime(d);
        c1.set(11, 0);
        c1.set(12, 0);
        c1.set(13, 0);
        c1.add(6, days);
        return c1.getTime();
    }

    public static Date getDateEndTime(Date d, int days) {
        Calendar c2 = Calendar.getInstance();
        c2.setTime(d);
        c2.set(11, 23);
        c2.set(12, 59);
        c2.set(13, 59);
        c2.add(6, days);
        return c2.getTime();
    }

    public static Date getFirstDayOfMonth(Date d) {
        Calendar c2 = Calendar.getInstance();
        c2.setTime(d);
        c2.set(5, 1);
        c2.set(11, 0);
        c2.set(12, 0);
        c2.set(13, 0);
        return c2.getTime();
    }

    public static Date getLastDayOfMonth(Date d) {
        Calendar c2 = Calendar.getInstance();
        c2.setTime(d);
        c2.set(5, c2.getActualMaximum(5));
        c2.set(11, 23);
        c2.set(12, 59);
        c2.set(13, 59);
        return c2.getTime();
    }

    public static Date addDate(Date d, int days) {
        Calendar c = Calendar.getInstance();
        c.setTime(d);
        c.add(6, days);
        return c.getTime();
    }

    public static int getDayOfDate(Date d) {
        Calendar c = Calendar.getInstance();
        c.setTime(d);
        return c.get(5);
    }

    public static boolean isNumeric1(String str) {
        return pattern.matcher(str).matches();
    }

    public static Date parseDateIgnoreCase(String dateStr) throws ParseException {
        return dateStr != null && !"".equalsIgnoreCase(dateStr) ? parse(dateStr, "yyyy-MM-dd") : null;
    }

    public static Date parseDate(String dateStr, String type) throws Exception {
        if (dateStr != null && !"".equalsIgnoreCase(dateStr)) {
            SimpleDateFormat dateFormat = new SimpleDateFormat(type);
            return dateFormat.parse(dateStr);
        } else {
            return null;
        }
    }

    public static String format(Date date, String fmt) {
        DateFormat formatter = new SimpleDateFormat(fmt);
        return formatter.format(date);
    }

    public static String format(Date date) {
        return date == null ? "" : format(date, "yyyy-MM-dd");
    }

    public static String formatCurrentDate() {
        return format(new Date(System.currentTimeMillis()), "yyyy-MM-dd");
    }

    public static Date getNow() {
        return new Date(System.currentTimeMillis());
    }

    public static Date getToday(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(11, 0);
        cal.set(12, 0);
        cal.set(13, 0);
        cal.set(14, 0);
        return cal.getTime();
    }

    public static Date getTodayLast(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(11, 23);
        cal.set(12, 59);
        cal.set(13, 59);
        cal.set(14, 999);
        return cal.getTime();
    }

    public static Date getSomeDate(Date date, int dayNum) {
        Calendar cal = Calendar.getInstance();
        long oneDayMs = 86400000L;
        cal.setTimeInMillis(date.getTime() + oneDayMs * (long)dayNum);
        return cal.getTime();
    }

    public static Date getSomeMonthDate(Date date, int monthNum) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(2, cal.get(2) + monthNum);
        return cal.getTime();
    }

    public static Date getSubsectionHourEnd(Date date, int sub) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(11, sub);
        cal.set(12, 59);
        cal.set(13, 59);
        cal.set(14, 999);
        return cal.getTime();
    }

    public static Date getTheDay(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(11, 0);
        cal.set(12, 0);
        cal.set(13, 0);
        cal.set(14, 0);
        return cal.getTime();
    }

    public static int getYear(Date date) {
        Calendar cld = Calendar.getInstance();
        cld.setTime(date);
        return cld.get(1);
    }

    public static int getMonth(Date date) {
        Calendar cld = Calendar.getInstance();
        cld.setTime(date);
        return cld.get(2);
    }

    public static int getDate(Date date) {
        Calendar cld = Calendar.getInstance();
        cld.setTime(date);
        return cld.get(5);
    }

    public static int getHour(Date date) {
        Calendar cld = Calendar.getInstance();
        cld.setTime(date);
        return cld.get(11);
    }

    public static int getMin(Date date) {
        Calendar cld = Calendar.getInstance();
        cld.setTime(date);
        return cld.get(12);
    }

    public static Date getThisWeekStart() {
        Calendar cal = Calendar.getInstance();
        cal.add(5, -(cal.get(7) - 1));
        return getTheDay(cal.getTime());
    }

    public static Date getThisMonthStart() {
        Calendar cal = Calendar.getInstance();
        cal.set(5, 1);
        return getTheDay(cal.getTime());
    }

    public static Date getMonthStart(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(5, 1);
        return getTheDay(cal.getTime());
    }

    public static Date getTheMonthStart(int amount) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(getThisMonthStart());
        cal.add(2, amount);
        return cal.getTime();
    }

    public static Date getThisMonthEnd() {
        Calendar cal = Calendar.getInstance();
        cal.set(5, cal.getActualMaximum(5));
        return getTodayLast(cal.getTime());
    }

    public static Date getMonthEnd(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(5, cal.getActualMaximum(5));
        return getTodayLast(cal.getTime());
    }

    public static int getMonthDay(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        return cal.getActualMaximum(5);
    }

    public static Date addMinute(Date date, int minute) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(12, minute);
        return new Date(cal.getTime().getTime());
    }

    public static Date addSecond(Date date, int second) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(13, second);
        return new Date(cal.getTime().getTime());
    }

    public static Date addHour(Date date, int hour) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(10, hour);
        return new Date(cal.getTime().getTime());
    }

    public static Date addDay(Date date, int day) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(5, day);
        return new Date(cal.getTime().getTime());
    }

    public static Date addMonth(Date date, int month) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(2, month);
        return new Date(cal.getTime().getTime());
    }

    public static Date addYear(Date date, int year) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.add(1, year);
        return new Date(cal.getTime().getTime());
    }

    public static int getDays(Date date1, Date date2) {
        int days = (int)(Math.abs(date2.getTime() - date1.getTime()) / 86400000L);
        return days;
    }

    public static int getSecond(Date date1, Date date2) {
        int second = (int)Math.abs((date1.getTime() - date2.getTime()) / 1000L);
        return second;
    }

    public static int getMinute(Date date1, Date date2) {
        int minute = (int)Math.abs((date1.getTime() - date2.getTime()) / 60000L);
        return minute;
    }

    public static int getCompareMinute(Date date1, Date date2) {
        int minute = (int)((date1.getTime() - date2.getTime()) / 60000L);
        return minute;
    }

    public static int getCompareDate(Date date1, Date date2) {
        int date = (int)((date1.getTime() - date2.getTime()) / 86400000L);
        return date;
    }

    public static int getCompareDateOnlyDay(Date date1, Date date2) {
        int date = (int)((date1.getTime() - date2.getTime()) / 86400000L);
        return date;
    }

    public static String getDayDif(Date date1, Date date2) {
        long oneDayMs = 86400000L;
        long between = Math.abs(date2.getTime() - date1.getTime());
        long day = between / oneDayMs;
        long hour = between / 3600000L - day * 24L;
        long min = between / 60000L - day * 24L * 60L - hour * 60L;
        long s = between / 1000L - day * 24L * 60L * 60L - hour * 60L * 60L - min * 60L;
        return "" + day + "天" + hour + "小时" + min + "分" + s + "秒";
    }

    public static Long getDateBetween(Date date1, Date date2, String type) {
        long between = Math.abs(date2.getTime() - date1.getTime());
        switch (type) {
            case "d":
                return between / 86400000L;
            case "h":
                return between / 3600000L;
            case "M":
                return between / 60000L;
            case "s":
                return between / 1000L;
            default:
                return 0L;
        }
    }

    public static Date[] getMonthStartAndEnd(String dateStr) throws Exception {
        Date[] date = new Date[2];
        if (StringUtils.isNotBlank(dateStr)) {
            Date datePar = parseDate(dateStr, "yyyy-MM-dd");
            date[0] = getFirstDayOfMonth(datePar);
            date[1] = getLastDayOfMonth(datePar);
        }

        return date;
    }

    public static Date getCurrentDay() {
        Calendar ca = Calendar.getInstance();
        ca.set(11, 0);
        ca.set(12, 0);
        ca.set(13, 0);
        ca.set(14, 0);
        return ca.getTime();
    }

    public static long getDayOfHour(long time) {
        Calendar ca = Calendar.getInstance();
        ca.setTimeInMillis(time);
        ca.set(12, 0);
        ca.set(13, 0);
        ca.set(14, 0);
        return ca.getTimeInMillis();
    }

    public static long addDayOfHour(long time, int hour) {
        Calendar ca = Calendar.getInstance();
        ca.setTimeInMillis(time);
        ca.add(11, hour);
        return ca.getTimeInMillis();
    }

    public static Date parseSimpleForMinute(String simpleDateStr) {
        if (StringUtils.isBlank(simpleDateStr)) {
            return null;
        } else {
            try {
                DateFormat simpleDateFormatForMinute = new SimpleDateFormat("yyyy-MM-dd HH:mm");
                return simpleDateFormatForMinute.parse(simpleDateStr);
            } catch (ParseException var2) {
                return null;
            }
        }
    }

    public static String getTimeStringForMinute(Long time) {
        DateFormat simpleDateFormatForMinute = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        return simpleDateFormatForMinute.format(new Date(time));
    }

    public static String getDateStringForMinute(Date date) {
        DateFormat simpleDateFormatForMinute = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        return simpleDateFormatForMinute.format(date);
    }

    public static Date parseSimple(String simpleDateStr) {
        DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if (StringUtils.isEmpty(simpleDateStr)) {
            return null;
        } else {
            try {
                return simpleDateFormat.parse(simpleDateStr);
            } catch (ParseException var3) {
                return null;
            }
        }
    }

    public static String getTimeString(Long time) {
        DateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return simpleDateFormat.format(new Date(time));
    }

    public static Long getTimeLong(Date date) {
        return date.getTime();
    }

    public static Date getCurrentTime() {
        return new Date();
    }

    public static String formatCurrentTime(String patten) {
        return formatDateToString(new Date(), patten);
    }

    public static String formatDateToString(Date date, String patten) {
        if (null == date) {
            return "";
        } else {
            SimpleDateFormat sd = new SimpleDateFormat(patten);
            return sd.format(date);
        }
    }

    public static String dateToString(Date date) {
        return date == null ? "" : dateToString(date, (String)null);
    }

    public static String dateToString(Date date, String format) {
        if (date == null) {
            return "";
        } else {
            return StringUtils.isBlank(format) ? DATE_TIME_FORMAT.format(date) : format(date, format);
        }
    }

    public static String formatDateNormal(Date date) {
        return null == date ? "" : format(date, "yyyy-MM-dd HH:mm:ss");
    }

    public static String formatDateNormal(Long date) {
        return null == date ? "" : format(new Date(date), "yyyy-MM-dd HH:mm:ss");
    }

    public static Date formatStrToDate(String dateStr, String patten) {
        if (StringUtils.isBlank(dateStr)) {
            return null;
        } else {
            try {
                return parse(dateStr, patten);
            } catch (ParseException var3) {
                return null;
            }
        }
    }

    public static Date formatStrToNormalDate(String dateStr) {
        return formatStrToDate(dateStr, "yyyy-MM-dd HH:mm:ss");
    }

    public static Date getDateByTimeString(Date date, String timeString) {
        timeString = formatDateToString(date, String.format("yyyy-MM-dd %s", timeString));
        return formatStrToDate(timeString, "yyyy-MM-dd HH:mm:ss");
    }

    public static Date getDayStart(Date date) {
        String dateStartString = formatDateToString(date, "yyyy-MM-dd 00:00:00");
        return formatStrToDate(dateStartString, "yyyy-MM-dd HH:mm:ss");
    }

    public static Integer getDayInt(Date date) {
        String dateStartString = formatDateToString(date, "yyyyMMdd");
        return Integer.parseInt(dateStartString);
    }

    public static Date getDayEnd(Date date) {
        String dateStartString = formatDateToString(date, "yyyy-MM-dd 23:59:59");
        return formatStrToDate(dateStartString, "yyyy-MM-dd HH:mm:ss");
    }

    public static Date getDay(Date date) {
        String dateStartString = formatDateToString(date, "yyyy-MM-dd 00:00:00");
        return formatStrToDate(dateStartString, "yyyy-MM-dd HH:mm:ss");
    }

    public static Date getDayYyyyMmDd(Date date) {
        String dateStartString = formatDateToString(date, "yyyy-MM-dd");
        return formatStrToDate(dateStartString, "yyyy-MM-dd");
    }

    public static Date getYesterday() {
        return getDayBefore(1);
    }

    public static Date getDayBefore(Integer day) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(5, calendar.get(5) - day);
        return calendar.getTime();
    }

    public static Date getDayBefore(Date date, Integer day) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(5, calendar.get(5) - day);
        return calendar.getTime();
    }

    public static Date getDayAfter(Date date, Integer day) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.set(5, calendar.get(5) + day);
        return calendar.getTime();
    }

    public static Date getMonthBefore(Integer month) {
        Calendar calendar = Calendar.getInstance();
        calendar.set(5, 1);
        calendar.add(2, -month);
        return calendar.getTime();
    }

    public static String getMonth() {
        String dateStartString = formatDateToString(new Date(), "yyyy-MM");
        return dateStartString;
    }

    public static boolean isMonthStart(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(5) == 1;
    }

    public static boolean isMonthEnd(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        calendar.add(5, 1);
        return calendar.get(5) == 1;
    }

    public static int getMonthDiff(Date bigDate, Date smallDate) {
        if (bigDate.compareTo(smallDate) <= 0) {
            return -1;
        } else {
            Calendar calInstance = Calendar.getInstance();
            calInstance.setTime(bigDate);
            int year1 = calInstance.get(1);
            int month1 = calInstance.get(2);
            calInstance.setTime(smallDate);
            int year2 = calInstance.get(1);
            int month2 = calInstance.get(2);
            return (year1 - year2) * 12 + month1 - month2;
        }
    }

    public static int getDayDiff(Date bigDate, Date smallDate) {
        if (bigDate.compareTo(smallDate) <= 0) {
            return -1;
        } else {
            Long diff = (bigDate.getTime() - smallDate.getTime()) / 86400000L;
            return diff.intValue();
        }
    }

    public static String getTimeZeroString(Long time) {
        DateFormat simpleDateTimeZeroFormat = new SimpleDateFormat("yyyy-MM-dd 00:00:00");
        return simpleDateTimeZeroFormat.format(new Date(time));
    }

    public static int compareDate(Date date1, Date date2) {
        if (date1.getTime() > date2.getTime()) {
            return 1;
        } else {
            return date1.getTime() < date2.getTime() ? -1 : 0;
        }
    }

    public static int diffDate(Date date, Date date1) {
        return (int)((getMillis(date) - getMillis(date1)) / 86400000L);
    }

    public static int diffYear(Date date, Date date1) {
        return (int)(Math.abs(getMillis(date) - getMillis(date1)) / 86400000L) / 365;
    }

    public static Long diffMillis(Date begin, Date end) {
        return end.getTime() - begin.getTime();
    }

    public static long getMillis(Date date) {
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c.getTimeInMillis();
    }

    public static boolean isNowBefore(Date checkDate) {
        Calendar checkCal = Calendar.getInstance(Locale.CHINA);
        Calendar nowCal = Calendar.getInstance(Locale.CHINA);
        checkCal.setTime(checkDate);
        nowCal.setTime(new Date());
        return nowCal.before(checkCal);
    }

    public static boolean isNowAfter(Date checkDate) {
        Calendar checkCal = Calendar.getInstance(Locale.CHINA);
        Calendar nowCal = Calendar.getInstance(Locale.CHINA);
        checkCal.setTime(checkDate);
        nowCal.setTime(new Date());
        return nowCal.after(checkCal);
    }

    public static boolean isNowBetween(Date beginDate, Date endDate) {
        Calendar beginCal = Calendar.getInstance(Locale.CHINA);
        Calendar nowCal = Calendar.getInstance(Locale.CHINA);
        Calendar endCal = Calendar.getInstance(Locale.CHINA);
        beginCal.setTime(beginDate);
        endCal.setTime(endDate);
        nowCal.setTime(new Date());
        return nowCal.after(beginCal) && nowCal.before(endCal);
    }

    public static Date convertToDateTime(String dateTimeString) {
        try {
            return DATE_TIME_FORMAT.parse(dateTimeString);
        } catch (ParseException var2) {
            return null;
        }
    }

    public static int getTodayLeftSecounds() {
        return (int)((getMillis(getDayEnd(new Date())) - getMillis(new Date())) / 1000L);
    }

    public static int getTodayLeftMiao() {
        Calendar curDate = Calendar.getInstance();
        Calendar tommorowDate = new GregorianCalendar(curDate.get(1), curDate.get(2), curDate.get(5) + 1, 0, 0, 0);
        return (int)(tommorowDate.getTimeInMillis() - curDate.getTimeInMillis()) / 1000;
    }

    public static String getNumberWeek(Date date) {
        String[] weeks = new String[]{"7", "1", "2", "3", "4", "5", "6"};
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        int weekIndex = cal.get(7) - 1;
        if (weekIndex < 0) {
            weekIndex = 0;
        }

        return weeks[weekIndex];
    }

    public static String getTimeString() {
        SimpleDateFormat df = new SimpleDateFormat(FORMAT_FULL);
        Calendar calendar = Calendar.getInstance();
        return df.format(calendar.getTime());
    }

    public static String getTimestampSecond(Date date) {
        return date == null ? null : StringUtils.substring(String.valueOf(date.getTime()), 0, 10);
    }

    public static int getMinute(Date date) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);
        return calendar.get(12);
    }

    public static boolean isSameDate(Date date1, Date date2) {
        if (date1 != null && date2 != null) {
            Calendar cal1 = Calendar.getInstance();
            cal1.setTime(date1);
            Calendar cal2 = Calendar.getInstance();
            cal2.setTime(date2);
            boolean isSameYear = cal1.get(1) == cal2.get(1);
            boolean isSameMonth = isSameYear && cal1.get(2) == cal2.get(2);
            boolean isSameDate = isSameMonth && cal1.get(5) == cal2.get(5);
            return isSameDate;
        } else {
            return false;
        }
    }

    public static boolean isSameDateTime(Date date1, Date date2) {
        if (date1 != null && date2 != null) {
            Calendar cal1 = Calendar.getInstance();
            cal1.setTime(date1);
            Calendar cal2 = Calendar.getInstance();
            cal2.setTime(date2);
            boolean isSameYear = cal1.get(1) == cal2.get(1);
            boolean isSameMonth = isSameYear && cal1.get(2) == cal2.get(2);
            boolean isSameDate = isSameMonth && cal1.get(5) == cal2.get(5);
            boolean isSameHour = isSameDate && cal1.get(11) == cal2.get(11);
            boolean isSameMinute = isSameHour && cal1.get(12) == cal2.get(12);
            return isSameMinute;
        } else {
            return false;
        }
    }

    public static Integer getDay() {
        Calendar cal = Calendar.getInstance();
        return cal.get(5);
    }

    public static Integer getDayByDate(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        return cal.get(5);
    }

    public static int diffHour(Date date, Date date2) {
        return (int)((getMillis(date) - getMillis(date2)) / 3600000L);
    }

    public static int diffMin(Date date, Date date2) {
        return (int)((getMillis(date) - getMillis(date2)) / 60000L);
    }

    public static String diffDateAfter(Date date, Date date2) {
        String dateAfter = null;
        Date currentDate = new Date();
        int day = diffDate(date, currentDate);
        if (day > 0) {
            if (date.getHours() - currentDate.getHours() <= 0) {
                ++day;
            }

            dateAfter = day + "天";
        } else if (day == 0) {
            day = diffHour(date, currentDate);
            if (day > 0) {
                dateAfter = day + "小时";
            } else {
                day = diffMin(date, currentDate);
                if (day > 0) {
                    dateAfter = day + "分钟";
                } else if (day == 0) {
                    dateAfter = "1分钟";
                }
            }
        }

        return dateAfter;
    }

    public static int getRemainSecondsToNextMonth() {
        Calendar calendar = Calendar.getInstance();
        long begin = calendar.getTimeInMillis();
        calendar.set(5, calendar.getActualMaximum(5));
        calendar.set(11, 23);
        calendar.set(12, 59);
        calendar.set(13, 59);
        calendar.set(14, 59);
        long end = calendar.getTimeInMillis();
        int result = (int)(end - begin) / 1000;
        return result;
    }

    public static Date getHourBegin(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(12, 0);
        cal.set(13, 0);
        cal.set(14, 0);
        return cal.getTime();
    }

    public static Date getHourEnd(Date date) {
        Calendar cal = Calendar.getInstance();
        cal.setTime(date);
        cal.set(12, 59);
        cal.set(13, 59);
        cal.set(14, 999);
        return cal.getTime();
    }

    public static Date getThisWeekFriday(Date date) {
        return getDayOfWeek(date, 6);
    }

    public static Date getNextWeekFriday(Date date) {
        Date thisFriday = getThisWeekFriday(date);
        return addDate(thisFriday, 7);
    }

    public static Date getDayOfWeek(Date date, int firstDayOfWeek) {
        Calendar cal = Calendar.getInstance();
        if (date != null) {
            cal.setTime(date);
        }

        cal.setFirstDayOfWeek(2);
        cal.set(7, firstDayOfWeek);
        cal.set(11, 0);
        cal.set(12, 0);
        cal.set(13, 0);
        cal.set(14, 0);
        return cal.getTime();
    }

    public static String date2String(Date date, String pattern) {
        SimpleDateFormat formatter = new SimpleDateFormat(pattern);
        String dateString = formatter.format(date);
        return dateString;
    }

    public static Date string2Date(String str, String pattern) {
        SimpleDateFormat formatter = new SimpleDateFormat(pattern);

        try {
            Date date = formatter.parse(str);
            return date;
        } catch (ParseException var4) {
            ParseException e = var4;
            e.printStackTrace();
            return null;
        }
    }

    public static Date string2Date(String str) {
        return string2Date(str, "yyyy-MM-dd HH:mm:ss");
    }

    public static Date longToDate(long currentTime) {
        Date date = new Date(currentTime);
        return date;
    }

    public static long date2Long(Date date) {
        long time = date.getTime();
        return time;
    }

    public static long string2Long(String str, String pattern) {
        return date2Long(string2Date(str, pattern));
    }

    public static String long2String(long str, String pattern) {
        return date2String(longToDate(str), pattern);
    }

    public static String localDateTime2String(LocalDateTime time, DateTimeFormatter df) {
        return df.format(time);
    }

    public static String localDateTime2String(LocalDateTime time) {
        return localDateTime2String(time, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
    }

    public static LocalDateTime string2LocalDateTime(String time, DateTimeFormatter df) {
        return LocalDateTime.parse(time, df);
    }

    public static LocalDateTime string2LocalDateTime(String time) {
        return string2LocalDateTime(time.substring(0, 19), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
    }

    public static Long betweenLocalDateTime(LocalDateTime d1, LocalDateTime d2) {
        return Duration.between(d1, d2).toDays();
    }

    public static Date convertToDate(Object obj, Date dDefault) {
        if (obj == null) {
            return dDefault;
        } else {
            String strSrc = SimpleStringUtil.convertToString(obj);
            if (StringUtils.isBlank(strSrc)) {
                return dDefault;
            } else {
                try {
                    if (Pattern.matches("^\\d{4}-\\d{2}-\\d{2} \\d{2}\\:\\d{2}\\:\\d{2}\\.\\d{3}$", strSrc)) {
                        return string2Date(strSrc, "yyyy-MM-dd HH:mm:ss.SSS");
                    }

                    if (Pattern.matches("^\\d{4}-\\d{2}-\\d{2} \\d{2}\\:\\d{2}\\:\\d{2}$", strSrc)) {
                        return string2Date(strSrc, "yyyy-MM-dd HH:mm:ss");
                    }

                    if (Pattern.matches("^\\d{4}-\\d{2}-\\d{2}$", strSrc)) {
                        return string2Date(strSrc, "yyyy-MM-dd");
                    }

                    if (Pattern.matches("^\\d+$", strSrc)) {
                        return new Date(SimpleStringUtil.convertToLong(strSrc));
                    }
                } catch (Exception var4) {
                }

                return dDefault;
            }
        }
    }

    public static Date max(Date dt1, Date dt2) {
        if (dt1 == null) {
            return dt2;
        } else if (dt2 == null) {
            return dt1;
        } else {
            return dt1.getTime() > dt2.getTime() ? dt1 : dt2;
        }
    }
}
